package com.shigen.demo.atguigu;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author shigenfu
 * @date 2022/5/31 9:39 下午
 */
public class AQSDemo {

  public static void main(String[] args) {
    ReentrantLock lock = new ReentrantLock();

    // 三个线程模拟AQS队列进行线程的管理和通知唤醒机制
    new Thread(() -> {
      lock.lock();
      try {
        System.out.println(Thread.currentThread().getName() + " ---come in");
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        e.printStackTrace();
      } finally {
        lock.unlock();
      }
    },"A").start();

    new Thread(() -> {
      lock.lock();
      try {
        System.out.println(Thread.currentThread().getName() + " ---come in");
      }finally {
        lock.unlock();
      }
    },"B").start();

    new Thread(() -> {
      lock.lock();
      try {
        System.out.println(Thread.currentThread().getName() + " ---come in");
      }finally {
        lock.unlock();
      }
    },"C").start();


  }
}
